package cn.skyquant.quant4j.jforex.sdk.strategy;

import cn.skyquant.quant4j.sdk.util.constant.EAConstants;
import cn.skyquant.quant4j.jforex.sdk.enums.OpenType;
import cn.skyquant.quant4j.sdk.util.time.CalendarUtils;

import java.util.Date;

public abstract class BaseOrderComment{
    public int series_id;       //加仓数列  0
    public int series_index ;   //加仓序号  1
    public OpenType type;        //加仓类型  2
    public int first_equit;     //首仓净值  3
    public Date first_time;     //首仓时间  4
    public int this_profitloss;//本次加仓时浮赢(亏)的钱 5
    public boolean valid;
    public int getParamNum(){return 6;};
    public String[] s;


    public BaseOrderComment() {
    }

    public void parse(String comment) {
        s = comment.split(EAConstants.split);
        if (s.length >= 6) {
            try {
                series_index = Integer.parseInt(s[0]);
                series_id = Integer.parseInt(s[1]);
                type = OpenType.valueOf(s[2]);
                first_equit = Integer.parseInt(s[3]);
                first_time = CalendarUtils.parseTight(s[4]);
                this_profitloss = Integer.parseInt(s[5]);
                valid = true;
            } catch (Exception e) {
                valid = false;
            }
        }
    }

    public BaseOrderComment(int series_id, int series_index, OpenType type, int first_equit, long first_time,int this_profitloss) {
        this.series_id = series_id;
        this.series_index = series_index;
        this.type = type;
        this.first_equit = first_equit;
        this.first_time = new Date(first_time);
        this.this_profitloss = this_profitloss;
    }

    public String toString() {
        return String.format("%d_%d_%s_%d_%s_%d",series_index,series_id,type.name(),first_equit,CalendarUtils.formatTight(first_time),this_profitloss);
    }
}
